﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GameEngineer.Vertex
{
    public class Vertex4:Vertex
    {
        public float mVertexX { get; set; }
        public float mVertexY { get; set; }
        public float mVertexZ { get; set; }
        public float mVertexW { get; set; }

        //求出向量的长度
        public float Length
        {
            get
            {
                return (float)Math.Sqrt(this.mVertexX * this.mVertexX + this.mVertexY * this.mVertexY + this.mVertexZ * this.mVertexZ);
            }
            private set { }
        }

        //求出单位向量
        public Vertex4 Normalized
        {
            get
            {
                return new Vertex4(mVertexX / Length, mVertexY / Length, mVertexZ / Length, this.mVertexW);
            }
            private set { }
        }

        public Vertex4() { }

        public Vertex4(float vertexX, float vertexY, float vertexZ,float vertexW)
        {
            this.mVertexX = vertexX;
            this.mVertexY = vertexY;
            this.mVertexZ = vertexZ;
            this.mVertexW = vertexW;
        }

        public Vertex4(Vertex4 otherVertex)
        {
            this.mVertexX = otherVertex.mVertexX;
            this.mVertexY = otherVertex.mVertexY;
            this.mVertexZ = otherVertex.mVertexZ;
            this.mVertexW = otherVertex.mVertexW;
        }
        
        //4维向量
        public override int Width()
        {
            return 4;
        }

        //叉乘（可以求法线）
        public Vertex4 Cross(Vertex4 otherVertex)
        {
            return new Vertex4(this.mVertexY * otherVertex.mVertexZ - this.mVertexZ * otherVertex.mVertexY, this.mVertexZ * otherVertex.mVertexX - this.mVertexX * otherVertex.mVertexZ, this.mVertexX * otherVertex.mVertexY - this.mVertexY * otherVertex.mVertexX, 1);
        }

        public static Vertex4 operator -(Vertex4 vertexA, Vertex4 vertexB)
        {
            return new Vertex4(vertexA.mVertexX - vertexB.mVertexX, vertexA.mVertexY - vertexB.mVertexY, vertexA.mVertexZ - vertexB.mVertexZ, 1);
        }

        //点积（可以求两向量角度）
        public float Dot(Vertex4 otherVertex)
        {
            return (float)(this.mVertexX * otherVertex.mVertexX + this.mVertexY * otherVertex.mVertexY + this.mVertexZ * otherVertex.mVertexZ);
        }
    }
}
